package cn.duyo.spring.beans.factory.config;

import cn.duyo.spring.beans.factory.HierarchicalBeanFactory;
import cn.duyo.spring.core.convert.ConversionService;
import cn.duyo.spring.util.StringValueResolver;
import com.sun.istack.internal.Nullable;

/**
 * 可获取 BeanPostProcessor、BeanClassLoader等的一个配置化接口
 *
 * @author du
 */
public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, SingletonBeanRegistry {

    String SCOPE_SINGLETON = "singleton";

    String SCOPE_PROTOTYPE = "prototype";

    void addBeanPostProcessor(BeanPostProcessor beanPostProcessor);

    /**
     * 可解析依赖
     * tips: ApplicationContext 本身不是通过 Bean 定义管理的对象，但通过此机制可将其作为依赖注入到其他 Bean 中，避免循环依赖问题‌
     *       当外部直接注入 ApplicationContext 时，不会再去bean容器寻找，直接从 DefaultListableBeanFactory#resolvableDependencies 这个map中寻找
     * @param dependencyType
     * @param autowiredValue
     */
    void registerResolvableDependency(Class<?> dependencyType, Object autowiredValue);

    /**
     * 销毁单例对象
     */
    void destroySingletons();

    /**
     * Add a String resolver for embedded values such as annotation attributes.
     * @param valueResolver the String resolver to apply to embedded values
     * @since 3.0
     */
    void addEmbeddedValueResolver(StringValueResolver valueResolver);

    /**
     * Resolve the given embedded value, e.g. an annotation attribute.
     * @param value the value to resolve
     * @return the resolved value (may be the original value as-is)
     * @since 3.0
     */
    String resolveEmbeddedValue(String value);


    /**
     * Specify a Spring 3.0 ConversionService to use for converting
     * property values, as an alternative to JavaBeans PropertyEditors.
     * @since 3.0
     */
    void setConversionService(ConversionService conversionService);

    /**
     * Return the associated ConversionService, if any.
     * @since 3.0
     */
    @Nullable
    ConversionService getConversionService();
}